package com.fitbet.entity.user;

import java.beans.Transient;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;

import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "user")
@PersistentFormat
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class User {
    
    @Id
    @GeneratedValue
    private Long id;

    private String mobile;
    
    private String gender;
    
    private String openid;
    
    private String unionid;
    
    private String name;
    
    private String nickname;
    
    private String avatar;
    
    private String email;
    
    private Date createTime;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public User() {
    
    }
    
    /**
     * 
     * @param unionid
     * @param openid
     * @param mobile
     */
    public User(String unionid, String openid, String mobile) {
        this.unionid = unionid;
        this.openid = openid;
        this.mobile =  mobile;
        this.createTime = new Date();
    }
    
    public User(String unionid, String mobile, String avatar, String gender) {
        this.unionid = unionid;
        this.avatar = avatar;
        this.mobile = mobile;
        this.gender = gender;
    }
    
    /**
     * @param mobile
     * @return
     */
    public User editMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }
    
    /**
     * 
     * @param openid
     * @return
     */
    public User bindOpenid(String openid) {
        this.openid = openid;
        return this;
    }
    
    /**
     * 
     * @param email
     * @return
     */
    public User bindEmail(String email) {
        this.email = email;
        return this;
    }
    
    /**
     * 
     * @param mobile
     * @return
     */
    public User bindMobile(String mobile) {
        this.mobile = mobile;
        return this;
    }
    
    
    /**
     * 
     * @param nickname
     * @param avatar
     * @return
     */
    public User initliaze(String nickname, String avatar) {
        this.nickname = nickname;
        this.avatar = avatar;
        
        return this;
    }

    /**
     * 
     * @return
     */
    @Transient
    public boolean hasEmail() {
        return StringUtils.isNotEmpty(this.email);
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the gender
     */
    public String getGender() {
        return gender;
    }

    /**
     * @return the openid
     */
    public String getOpenid() {
        return openid;
    }

    /**
     * @return the unionid
     */
    public String getUnionid() {
        return unionid;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the nickname
     */
    public String getNickname() {
        return nickname;
    }

    /**
     * @return the avatar
     */
    public String getAvatar() {
        return avatar;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param gender the gender to set
     */
    public void setGender(String gender) {
        this.gender = gender;
    }

    /**
     * @param openid the openid to set
     */
    public void setOpenid(String openid) {
        this.openid = openid;
    }

    /**
     * @param unionid the unionid to set
     */
    public void setUnionid(String unionid) {
        this.unionid = unionid;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param nickname the nickname to set
     */
    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
